package rxb.demo.wzycontroller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import rxb.demo.wzyentity.Food;
import rxb.demo.wzyservice.IFoodService;

import java.util.List;

/**
 * Created by Administrator on 2019/12/25 0025.
 */
@Controller
public class WzyIndexController {

    @Autowired
    private IFoodService foodService;

    @GetMapping("/wzyindex")
    public String index(Model model){

        //springboot - springmvc - servlet
        //为什么访问jsp需要通过后台去访问？？？

        //转发到jsp

        //调用service - dao层 - 和数据库进行交互 - 获取数据库中的数据
        //然后将数据放入到作用域中。
        List<Food> foods=foodService.findAll();

        //将得到的菜品的集合放入到request作用域中去
        model.addAttribute("foods",foods);

        return "wzyindex/wzy-index";
    }
}
